<?php
    header("Content-type:text/html;charset=utf-8");
    if ($_POST) {
        include '../../api/config.php';
        include './comm.php';
        $json = $_POST["data"];
        $data = json_decode($json);
        $id = $data->head;

        if ($id == '1042') {
            $name = $data->name;
            $flag = $data->flag1;
            $sql8 = "INSERT INTO tag(name,flag) VALUES('{$name}','{$flag}')";//新建
            $name = $data->name;
            if ($name != '') {
                if (flag($data)) {
                    $stmt4 = $conn->prepare($sql8);
                    $stmt4->execute();
                    $result4 = $stmt4->setFetchMode(PDO::FETCH_ASSOC);
                    echo get_msg('200','操作成功~',false,false);
                } else {
                    echo get_msg('500','权限不足~','../index.html',false);
                }
            }
        }
        //新建
        if ($id == '1043') {
            $name = $data->name;
            $flag = $data->flag;
            $ids = $data->ids;
            $sql9 = "UPDATE tag SET name='{$name}',flag='{$flag}' WHERE id='{$ids}'";//编辑
            if (flag($data)) {
                $stmt5 = $conn->prepare($sql9);
                $stmt5->execute();
                $result5 = $stmt5->setFetchMode(PDO::FETCH_ASSOC);
                echo get_msg('200','操作成功~',false,false);
            } else {
                echo get_msg('500','权限不足~','../index.html',false);
            }
        }
        //编辑
        if ($id == '1041') {
            $ids = $data->ids;
            $sql2 = "DELETE FROM tag WHERE id = '{$ids}'";//删除
            if (flag($data)) {
                $stmt2 = $conn->query($sql2);
                $stmt2->execute();
                $result2 = $stmt2->setFetchMode(PDO::FETCH_ASSOC);
                
                echo get_msg('200','操作成功~',false,false);
            } else {
                echo get_msg('500','权限不足~','../index.html',false);
            }
        }
        //删除
        // 输出内容
        if ($id == '1040') {
            $sql1 = "SELECT * FROM tag";//查询分类
            if (flag($data)) {
                $arr1 = array();
                $arr1['data'] = array();
                $stmt1 = $conn->query($sql1);
                $stmt1->execute();
                $result1 = $stmt1->setFetchMode(PDO::FETCH_ASSOC);
                $arr1['data'] = $stmt1->fetchAll();
                if ($result1) {
                    echo get_msg('200','操作成功~',false,$arr1['data']);
                } else {
                    echo get_msg('400','数据异常~',false,false);
                }
            } else {
                echo get_msg('500','权限不足~','../index.html',false);
            }
        }
        // 输出内容
        $conn = null;
    } else {
        echo "<script>\r\n    window.location.href = '../../';\r\n    </script>";
    }